<template>
	<view class="service-bar">
		<view class="service-title">
			专属服务
		</view>
		<view class="service-list-wrapper">
			<!-- 			<view class="service-item" v-for="(item,index) in 4" :style="{'background-position':`${-index*308}rpx 0px`}"
				@click="test">
			</view> -->
			<view class="service-item" v-if="serviceBarData[0]">
				<u-image :src="serviceBarData[0].icon" width="100%" height="100%" @click="toChatDetail(serviceBarData[0])"/>
			</view>
			<view class="service-item">
				<u-image  src="https://vkceyugu.cdn.bspapp.com/VKCEYUGU-8acfaa58-aeb5-4502-8309-365d4c6cca4a/271b8ad8-3366-42f1-8dbf-34243f1d9cf4.png" width="100%" height="100%" @click="toRecommended"/>
			</view>
			<view class="service-item" v-if="serviceBarData[2]">
				<u-image :src="serviceBarData[2].icon" width="100%" height="100%" @click="toChatDetail(serviceBarData[2])"/>
			</view>
			<view class="service-item" v-if="serviceBarData[3]">
				<u-image :src="serviceBarData[3].icon" width="100%" height="100%" @click="toChatDetail(serviceBarData[3])"/>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {}
		},
		props: {
			serviceBarData: {
				type: Array,
			}
		},
		methods: {
			async toChatDetail(item) {
				console.log(item)
				if (this.userInfo && (this.userInfo.is_lawyer == 1 || this.userInfo.is_service == 1)) {
					return this.$showToast('律师身份不能发起咨询')
				}
				this.$u.post(this.$restUrl.consultTimepiece, {
					type_id: item.id,
				}).then(res => {
					const session = {
						sessionId: res.data.groupid,
						sessionName: this.userInfo.nickname+'的'+item.title + '咨询',
						chatType: 'groupChat',
					}

					this.$u.route(`/pages_chat/chat_detail/chatDetail?sessionInfo=${encodeURIComponent(JSON
				.stringify(session))}`);
				}).catch(err => {
					if (err.status_code == 404) {
						const session = {
							sessionName: `${item.title}咨询`,
							quick_reply: item.quick_reply,
							quick_reply_second: item.quick_reply_second,
							quick_reply_third:item.quick_reply_third,
							id: item.id,
						}
						this.$u.route(`/pages_chat/static_chat/staticChat?sessionInfo=${encodeURIComponent(JSON
						.stringify(session))}`);
					}
				})
			},
			toRecommended(){
				this.$u.route('/pages_recommended/criminal_law/criminalLaw')
			}
		}
	}
</script>

<style scoped lang="scss">
	@import "./serviceBar.scss";
</style>
